package lemon.dog.common;

import lombok.Data;

@Data
public class R<T> {
    private String message;
    private T data;
    private Integer code;
    private R(String message, T data, Integer code) {
        this.message = message;
        this.data = data;
        this.code = code;
    }
    private R(String message) {
        this.message = message;
        this.code = 0;
    }

    public static <T> R<T> success(T data) {
        return new R<>("成功", data, 0);
    }

    public static <T> R<T> success(T data, String msg) {
        return new R<>(msg, data, 0);
    }
    public static <T> R<T> success(String msg) {
        return new R<>(msg);
    }

    public static R success() {
        return new R<>("成功", null, 0);
    }

    public static R error() {
        return new R<>("失败", null, -1);
    }

    public static R error(ErrorEnum ee) {
        return new R<>(ee.getMessage(), null, ee.getCode());
    }
}
